package com.example.chat.model;

import com.example.chat.constant.StaticConstant;
import com.example.chat.type.ApprovalStatus;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

@Entity
@Data
@Table(name = "VDOA021_ASSETS_REQUEST_RECORD")
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@DynamicInsert
@DynamicUpdate
@NoArgsConstructor
public class AssetsRequestRecord extends BaseEntity implements Serializable {

    private static final long serialVersionUID = -2477080999160273610L;

    @Id
    @GenericGenerator(name = "uuidG", strategy = "org.hibernate.id.UUIDGenerator")
    @GeneratedValue(generator = "uuidG")
    @Column(name = "DOA021_ID", length = 50)
    private String id;

    /**
     * 申请单编号
     */
    @Column(name = "DOA021_DOCUMENT_NUMBER")
    private String documentNumber;

    /**
     * 资产申请时间（搜索使用）
     */
    @Column(name = "DOA021_REQUEST_DATE")
    @Temporal(TemporalType.DATE)
    @JsonFormat(pattern = StaticConstant.DATE_FORMAT, timezone = StaticConstant.GMT8)
    private Date requestDate = new Date();

    /**
     * 资产申请具体时间
     */
    @Column(name = "DOA021_REQUEST_DETAIL_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = StaticConstant.DOA_DATE_FORMAT, timezone = StaticConstant.GMT8)
    private Date requestDetailDate = new Date();

    /**
     * 申请设备名称
     */
    @Column(name = "DOA021_EQUIP_MENT_TYPE_ID")
    private String equipMentTypeId;

    @JoinColumn(name = "DOA021_EQUIP_MENT_TYPE_ID", insertable = false, updatable = false)
    @ManyToOne(fetch = FetchType.LAZY, targetEntity = EquipMentType.class)
    private EquipMentType equipMentType;

    @Column(name = "DOA021_EQUIP_MENT_TYPE_NAME")
    private String equipMentTypeName;
    /**
     * 申请设备id
     */
    @Column(name = "DOA021_REQUEST_ASSETS_ID")
    private Integer requestAssetsId;

    @ManyToOne(targetEntity = Assets.class, fetch = FetchType.LAZY)
    @JoinColumn(name = "DOA021_REQUEST_ASSETS_ID", insertable = false, updatable = false)
    private Assets assets;
    /**
     * 申请用途
     */
    @Column(name = "DOA021_REQUEST_USE")
    private String requestUse;

    /**
     * 审批人
     */
    @Column(name = "DOA021_APPROVAL_EMP_ID")
    private String approvalEmpId;

    @ManyToOne(targetEntity = Employee.class, fetch = FetchType.LAZY)
    @JoinColumn(name = "DOA021_APPROVAL_EMP_ID", insertable = false, updatable = false)
    private Employee approvalEmp;

    @Column(name = "DOA021_APPROVAL_EMP_NAME")
    private String approvalEmpName;

    /**
     * 审批状态
     */
    @Column(name = "DOA021_APPROVAL_STATUS")
    @Enumerated(value = EnumType.STRING)
    private ApprovalStatus approvalStatus = ApprovalStatus.ING;

    /**
     * 员工
     */
    @JoinColumn(name = "DOA021_EMPLOYEE_ID", insertable = false, updatable = false)
    @OneToOne(targetEntity = Employee.class, fetch = FetchType.LAZY)
    private Employee employee;

    /**
     * 员工ID
     */
    @Column(name = "DOA021_EMPLOYEE_ID")
    private String employeeId;

    @Column(name = "DOA021_EMP_NAME")
    private String empName;

    /**
     * 申请人职位
     */
    @JoinColumn(name = "DOA021_POSITION_ID", insertable = false, updatable = false)
    @OneToOne(targetEntity = Position.class, fetch = FetchType.LAZY)
    private Position position;

    /**
     * 申请人职位ID
     */
    @Column(name = "DOA021_POSITION_ID")
    private String positionId;

    @Column(name = "DOA021_POSITION_NAME")
    private String positionName;

    /**
     * 备注
     */
    @Column(name = "DOA021_DESCRIPTION")
    private String description;

    /**
     * 提交资产申请单的员工
     */
    @Column(name = "DOA021_RECORD_SUBMIT_EMP")
    private String submitEmpId;

    @JoinColumn(name = "DOA021_RECORD_SUBMIT_EMP", insertable = false, updatable = false)
    @OneToOne(targetEntity = Employee.class, fetch = FetchType.LAZY)
    private Employee submitEmp;

    /**
     * 固定资产审批 拒绝理由详情
     */
    @Column(name = "DOA021_REJECT_REASON_DESCRIPTION")
    private String rejectReasonDescription;

    /**
     * 是否已删除
     */
    @Column(name = "DOA021_DELETED")
    private Boolean deleted = false;

    @Column(name = "DOA021_SORT")
    private Integer sort = ApprovalStatus.ING.ordinal();
}